﻿// Configuration.
var HOST_NAME = "http://api.tipons.com:9099";
var MERCHANT_PAGE = "http://www.tipons.com/view_merchants/{0}.html";
var FADE_TIME = 5000;

/**
* Format params to use for AJAX calls.
*/
function formatParams(p) {
    var queryStr = "";

    for (var propertyName in p) {
        var val = p[propertyName];
        queryStr += propertyName + "=" + encodeURI(val) + "&";
    }

    return queryStr.slice(0, -1);
}

/**
* Format params with patterns. Just like sprintf (C) or String.format (Java)
*/
String.format = function () {
    var s = arguments[0];
    for (var i = 0; i < arguments.length - 1; i++) {
        var reg = new RegExp("\\{" + i + "\\}", "gm");
        s = s.replace(reg, arguments[i + 1]);
    }
    return s;
}

/**
* Check whether Internet connection is available.
*/
function checkInternetConnection() {
    // Check if Internet connection is available.
    var isOnline = navigator.onLine;
    //var isOnline = false;
    console.log("isOnline: " + isOnline);

    // Show listView if Internet is avaible. Otherwise, show error message.
    if (isOnline) {
        $("#mainContainer").show();
        $("#errorMessageContainer").hide();
    } else {
        $("#mainContainer").hide();
        $("#errorMessageContainer").show();
    }

    return isOnline;
}